import{
	initOssUserClient,
	checkOssUserClient
} from '../utils/frontupload';

const frontDeleteFileMixin = {
	methods: {
		// 图片上传至 oss
		async deletefrontMultiFile(filearr, bucket = "newxuejinguser") {
			if (filearr.length == 0) {
				this.$dialog.alert({message:`没有文件可以删除`});
				return;
			}
			// 检查是否已有 Oss Client
			if (bucket == "newxuejinguser") {
				var client = checkOssUserClient();
				if (client === null) {
					try {
                        var res = await this.$frontaxios.get(this.$front.getStsUserToken);
						console.log(res)
						if (res.code == 1) {
							let oss = res.data;
							if (oss.statusCode == 200) {
								client = initOssUserClient(
									oss['accessKeyId'],
									oss['accessKeySecret'],
									oss['securityToken'],
									oss['expiration'],
									bucket
								);
								console.log(bucket)
							}
						} else {
							this.$toast.fail('请重新登录');
							this.$router.push({name:'my'});
						}
					} catch (error) {
						this.$toast.fail(`${error}`);
						return;
					}
				}
				//console.log(videoclient);return;
				try {
					const res1 = await client.deleteMulti(filearr);
					//console.log(res1);
					if (res1.deleted) {
						this.$toast.success('删除成功');
					}
				} catch (error) {
					this.$toast.fail(`${error}`);
				}

			}
		}
	}
};

export default frontDeleteFileMixin;
